package text;

import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class MyJFrame2 extends JFrame {
    //创建一个按钮对象
    JButton jtb1 = new JButton("开始游戏");

    public MyJFrame2(){
        this.setSize(603,680);
        this.setTitle("拼图单机版 v1.0");
        this.setAlwaysOnTop(true);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        this.setLayout(null);

        jtb1.setBounds(0,0,100,50);
        //给按钮绑定MouseListener事件
        jtb1.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {
                System.out.println("鼠标点击");
            }

            @Override
            public void mousePressed(MouseEvent e) {
                System.out.println("鼠标按住不松");
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                System.out.println("鼠标释放");
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                System.out.println("鼠标划入");
            }

            @Override
            public void mouseExited(MouseEvent e) {
                System.out.println("鼠标划出");
            }
        });

        //把按钮添加到隐藏容器当中,影藏容器的获得用gteContentPane()方法,再使用链式法则
        this.getContentPane().add(jtb1);

        this.setVisible(true);
    }
}
